Conditions | 27 |
Total Lines | 101 |
Code Lines | 91 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like GamePage.render often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | import React, { Component, Fragment } from "react" |
||
62 | |||
63 | render() { |
||
64 | if (this.matchId === null) { |
||
65 | return ( |
||
66 | <Layout> |
||
67 | <section className="grid-container site-content">Geen match beschikbaar...</section> |
||
68 | </Layout> |
||
69 | ) |
||
70 | } |
||
71 | |||
72 | moment.locale(`nl-be`) |
||
73 | |||
74 | if (this.state.loading === false && this.state.data) { |
||
75 | const { general = {}, substitutes = {}, lineup = {}, events = [] } = this.state.data |
||
76 | const homeTeamId = general.homeClub?.id |
||
77 | const ogImage = { |
||
78 | src: general?.homeClub?.logo, |
||
79 | width: 180, |
||
80 | height: 180, |
||
81 | } |
||
82 | |||
83 | const { home: homeLineup = [], away: awayLineup = [] } = lineup || {} |
||
84 | const { home: homeSubs = [], away: awaySubs = [] } = substitutes || {} |
||
85 | |||
86 | const matchTime = moment(general.date) |
||
87 | |||
88 | return ( |
||
89 | <Layout> |
||
90 | <SEO |
||
91 | lang="nl-BE" |
||
92 | title={`Matchverslag ${general?.homeClub?.name} - ${general?.awayClub?.name}`} |
||
93 | description={`Matchverslag ${general?.homeClub?.name} - ${general?.awayClub?.name}`} |
||
94 | path={`/game/${general?.id}`} |
||
95 | image={ogImage} |
||
96 | /> |
||
97 | |||
98 | <section className="grid-container game-stats"> |
||
99 | <div className="grid-x grid-margin-x"> |
||
100 | <div className={`cell large-12 center game__details`}> |
||
101 | <div className="game__teams"> |
||
102 | <div className={`game__teams-inner`}> |
||
103 | <LazyLoad debounce={false}> |
||
104 | <img src={general.homeClub?.logo} alt={general.homeClub?.name} title={general.homeClub?.name} /> |
||
105 | </LazyLoad> |
||
106 | </div> |
||
107 | {this.renderScore(general.goalsHomeTeam, general.goalsAwayTeam)} |
||
108 | <div className={`game__teams-inner`}> |
||
109 | <LazyLoad debounce={false}> |
||
110 | <img src={general.awayClub?.logo} alt={general.awayClub?.name} title={general.awayClub?.name} /> |
||
111 | </LazyLoad> |
||
112 | </div> |
||
113 | </div> |
||
114 | <h1>{`${general.homeClub?.name} - ${general.awayClub?.name}`}</h1> |
||
115 | <h4>{general.competitionType}</h4> |
||
116 | <time dateTime={matchTime.format(`YYYY-MM-DD - H:mm`)}> |
||
117 | {matchTime.format(`dddd DD MMMM YYYY - H:mm`)} |
||
118 | </time> |
||
119 | <br /> |
||
120 | |||
121 | {general.status !== 0 && ( |
||
122 | <span className={`game__status game__status--${general.status}`}>{mapPsdStatus(general.status)}</span> |
||
123 | )} |
||
124 | |||
125 | <br /> |
||
126 | </div> |
||
127 | {(homeLineup.length !== 0 || awayLineup.length !== 0) && ( |
||
128 | <div className={`lineup__wrapper grid-x grid-margin-x cell large-12`}> |
||
129 | <div className={`cell large-6 lineup__wrapper--home`}> |
||
130 | <h3>{general.homeClub?.name}</h3> |
||
131 | {homeLineup && this.renderLineup(homeLineup, homeSubs)} |
||
132 | </div> |
||
133 | <div className={`cell large-6 lineup__wrapper--away`}> |
||
134 | <h3>{general.awayClub?.name}</h3> |
||
135 | {awayLineup && this.renderLineup(awayLineup, awaySubs)} |
||
136 | </div> |
||
137 | </div> |
||
138 | )} |
||
139 | |||
140 | {events.length !== 0 && ( |
||
141 | <div className={`cell large-12 event__wrapper`}> |
||
142 | <h3>Gebeurtenissen</h3> |
||
143 | {events && this.renderEvents(events, homeTeamId)} |
||
144 | </div> |
||
145 | )} |
||
146 | </div> |
||
147 | </section> |
||
148 | |||
149 | <MiniRanking |
||
150 | teamId={general.homeTeamId || general.awayTeamId} |
||
151 | homeTeam={general.homeClub?.name} |
||
152 | awayTeam={general.awayClub?.name} |
||
153 | /> |
||
154 | </Layout> |
||
155 | ) |
||
156 | } else { |
||
157 | return ( |
||
158 | <Layout> |
||
159 | <section className="grid-container site-content"> |
||
160 | <Spinner /> |
||
161 | </section> |
||
162 | </Layout> |
||
163 | ) |
||
322 |